package cn.org.zx.common.commutils;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

import cn.org.zx.common.commutils.DateUtils;

public class DBTimeServer {	
	//取当前时间
	private static Object getServerTime(String timeType) {
		Calendar systime = Calendar.getInstance();
		if ("calendar".equalsIgnoreCase(timeType))
			return systime;
		else if ("timestamp".equalsIgnoreCase(timeType))
			return DateUtils.convUtilCalendarToSqlTimestamp(systime);
		else
			return systime.getTime();
	}
	
	public static Timestamp getServerTimestamp() { 
		return (Timestamp) getServerTime("timestamp");
	}
	
	public static Calendar getServerCalendar() {
		return (Calendar) getServerTime("calendar");
	}


	public static Date getServerDate() {
		return (Date)getServerTime(null);
	}	
	
	public static void main(String args[])
	{
		try
        {	
			
			System.out.println(getServerDate());
			System.out.println(getServerTimestamp().toString().substring(0, 4)+getServerTimestamp().toString().substring(5, 7)+getServerTimestamp().toString().substring(8, 10));
			System.out.println(getServerCalendar().toString());
        }
        catch(Exception ex){ 
			ex.printStackTrace();
		}
    }
}
